﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web_HengliSeed.Sys_Manage
{
    public partial class M_UserLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Common.SetMes.RemoveSession("UserID");
            }
        }

        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            if (CheckNull())
            {
                if (Common.GetMes.GetCheckResult("CheckCode", txtU_Check.Value.Trim()))
                {
                    if (Common.GetMes.GetConfigAppValue("AdminName").Equals(txtU_Name.Value.Trim()))
                    {
                        if (BLL.AdminUser.CheckUserLogin(txtU_Name.Value, txtU_Pass.Value.Trim()))
                        {
                            Common.SetMes.SetSession("UserID", txtU_Name.Value);
                            BLL.SysLog.AddSysLog("【登录成功】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 1);
                            Response.Redirect("Index.aspx");
                        }
                        else
                        {
                            BLL.SysLog.AddSysLog("【登录失败】，密码有误！" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 1);
                            Common.ShowMessage.Show(Page, "Error1", "验证密码有误，请重新登录...", "M_UserLogin.aspx");
                        }
                    }
                    else
                    {
                        BLL.SysLog.AddSysLog("【登录失败】，用户名有误！" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 1);
                        Common.ShowMessage.Show(Page, "Error2", "验证用户名有误，请重新登录...。", "M_UserLogin.aspx");
                    }
                }
                else
                {
                    Common.ShowMessage.Show(Page, "Error3", "验证码有误，请看清图片上的数字。", "M_UserLogin.aspx");
                }
            }
        }
        private bool CheckNull()
        {
            return (!(string.IsNullOrEmpty(txtU_Name.Value.Trim())) && !(string.IsNullOrEmpty(txtU_Pass.Value.Trim())) && !(string.IsNullOrEmpty(txtU_Check.Value.Trim()))) ? true : false;
        }
    }
}
